﻿using System;
using System.Collections.Generic;
using System.Text;
using Spring.Context;
using Spring.Context.Support;
using AppToolKit.Core.Context.Spring;
using BLL.Action.Job;

namespace CenterDateAchieve
{
    class GenericApp
    {
        private JobFaced JobFacedHolder = null;

        // Methods
        public void OnStart()
        {
            try
            {
                IApplicationContext context = ContextRegistry.GetContext();
                ContextAware contextWrapper = (ContextAware)context.GetObject("ContextAwareSlot");
                string propertiesFile = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + @"\spring.properties.config";
                AutoWiringFactory.SetContext(contextWrapper);
                this.JobFacedHolder = (JobFaced)context.GetObject("jobFacedHolder");
                this.JobFacedHolder.AutoRun();
            }
            catch (Exception)
            {
                this.JobFacedHolder.AutoStop();
                ContextRegistry.GetContext().Dispose();
                throw;
            }
        }

        public void OnStop()
        {
            this.JobFacedHolder.AutoStop();
            ContextRegistry.GetContext().Dispose();
        }

    }
}
